package com.jblog.core.model.blog;

import com.jblog.common.util.MD5;
import com.jblog.core.model.BaseModel;
import com.jblog.core.model.common.Status;

/**
 * Post Comment
 */
public class Comment extends BaseModel {

	private static final long serialVersionUID = 1L;

	private Post post;
	private String commentator;
	private String email;
	private String link;
	private String photo;
	private String ip;
	private String comment;
	private Integer good = 0;
	private Integer bad = 0;
	private Boolean isSend = false;
	private Status status;
	
	//--------------------------
	private String captcha;
	

    public Comment() {
        super();
    }

    public Comment(Long id) {
        super(id);
    }

    public Comment(Long id, Status status) {
        super(id);
        this.status = status;
    }

    public Post getPost() {
		return post;
	}

	public void setPost(Post post) {
		this.post = post;
	}

	public String getCommentator() {
        return commentator;
    }

    public void setCommentator(String commentator) {
        this.commentator = commentator;
    }

    public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getLink() {
		return link;
	}

	public void setLink(String link) {
	    if ("".equals(link))
	        this.link = null;
	    else
	        this.link = link;
	}

	public String getPhoto() {
        return photo;
    }

    public void setPhoto(String photo) {
        this.photo = photo;
    }

    public String getComment() {
        return comment;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public Integer getGood() {
        return good;
    }

    public void setGood(Integer good) {
        this.good = good;
    }

    public Integer getBad() {
        return bad;
    }

    public void setBad(Integer bad) {
        this.bad = bad;
    }

    public String getIp() {
		return ip;
	}
	public String getShortIp() {
        int i = ip.lastIndexOf(".");
        return ip.substring(0, i) + ".*";
    }

	public void setIp(String ip) {
		this.ip = ip;
	}

	public Boolean getIsSend() {
		return isSend;
	}

	public void setIsSend(Boolean isSend) {
		this.isSend = isSend;
	}

	public Status getStatus() {
		return status;
	}

	public void setStatus(Status status) {
		this.status = status;
	}
	

    public String getCaptcha() {
        return captcha;
    }

    public void setCaptcha(String captcha) {
        this.captcha = captcha;
    }
    
    public String getHex() {
        return MD5.code(getEmail());
    }

    @Override
    public String toString() {
        return "Comment [post=" + post + ", commentator=" + commentator + ", id=" + getId() + "]";
    }

}